﻿// ***********************************************************************
// Assembly         : OSS.BIM
// Author           : TianTeng
// Created          : 09-03-2018
//
// Last Modified By : TianTeng
// Last Modified On : 09-03-2018
// ***********************************************************************
// <copyright file="BmConfigUtil.cs" company="北京智帆高科科技有限公司">
//     Copyright © 北京智帆高科科技有限公司 2018
// </copyright>
// <summary></summary>
// ***********************************************************************
using System.IO;
using System.Reflection;
using ZFGK.IO;
using ZFGK.IO.FileConfigs;
using ZFGK.Sys;
using ZFGK.Utility;

namespace OSS.BIM.Utility
{
    /// <summary>
    /// Class BmConfigUtil.
    /// </summary>
    public static class BmConfigUtil
    {
        #region 路径
        /// <summary>
        /// 当前dll路径
        /// </summary>
        public static readonly string CurPath = Assembly.GetExecutingAssembly().FolderPath();
        /// <summary>
        /// The configuration path
        /// </summary>
        public static readonly string AppDataPath = Path.Combine(EnvironmentUtil.ApplicationDataPath(), "OSS.BIM");

        /// <summary>
        /// The raw dem path
        /// </summary>
        public static readonly string RawDemPath = Path.Combine(AppDataPath, "RawDem");

        /// <summary>
        /// 用户模型目录.
        /// </summary>
        /// <value>The user model path.</value>
        public static string ModelsPath { get { return Path.Combine(AppDataPath, "UserModelFile"); } }

        /// <summary>
        /// 获得项目配置文件.
        /// </summary>
        /// <returns>System.String.</returns>
        public static string GetConfigFilePath()
        {
            return PathUtil.Combine(AppDataPath, "BimManagerConfig.ini");
        }

        /// <summary>
        /// 获得项目配置文件.
        /// </summary>
        /// <returns>IniFile.</returns>
        public static IniFile GetConfigFile()
        {
            return new IniFile(GetConfigFilePath());
        }

        /// <summary>
        /// Gets the configuration file.
        /// </summary>
        /// <param name="curField">The current field.</param>
        /// <returns>IniFile.</returns>
        public static IniFile GetConfigFile(string curField)
        {
            return new IniFile(GetConfigFilePath(), curField);
        }

        /// <summary>
        /// Gets the name of the company.
        /// </summary>
        /// <returns>System.String.</returns>
        public static string GetCompanyName()
        {
            return GetConfigFile().GetValueOfKey("Project", "CompanyName");
        }

        /// <summary>
        /// 数据库路径.
        /// </summary>
        /// <returns>System.String.</returns>
        public static string GetDatabasePath()
        {
            return Path.Combine(AppDataPath, "BIM.db");
        }

        /// <summary>
        /// Caches the path.
        /// </summary>
        /// <returns>System.String.</returns>
        public static string CachePath()
        {
            return PathUtil.Combine(AppDataPath, "Cache");
        }

        /// <summary>
        /// 坐标轴模型路径
        /// </summary>
        /// <returns>System.String.</returns>
        public static string GetAxesModelPath()
        {
            return Path.Combine(CurPath, "Model", "axes.osgt");
        }

        /// <summary>
        /// Gets the location path.
        /// </summary>
        /// <returns>System.String.</returns>
        public static string GetLocationImagePath()
        {
            return PathUtil.Combine(CurPath, "icons\\location.png");
        }


        /// <summary>
        /// Gets the base database path.
        /// </summary>
        /// <returns>System.String.</returns>
        public static string GetBaseDatabasePath()
        {
            return Path.Combine(Assembly.GetExecutingAssembly().FolderPath(), "database", "BIM.db");
        }

        #endregion

        #region 配置

        /// <summary>
        /// The configuration
        /// </summary>
        public static BmConfig BaseConfig = new BmConfig();

        /// <summary>
        /// 配置文件
        /// </summary>
        public static ClassIniConfig ClassIniConfig = new ClassIniConfig(GetConfigFile(), "BaseConfig", BaseConfig);

        /// <summary>
        /// 加载所有的配置项.
        /// </summary>
        public static void LoadAllConfig()
        {
            ClassIniConfig.Laod();
        }

        /// <summary>
        /// 保存所有的配置项.
        /// </summary>
        public static void SaveAllConfig()
        {
            ClassIniConfig.Save();
        }

        #endregion
    }
}
